<?php
namespace Home\Model;
use Think\Model;

class UserModel extends Model
{
	protected $_validate = array(
		array('username','require','账号不能为空！'),
		array('branch','require','部门名不能为空！'),
		array('password','require','密码不能为空！'),
		array('username','checkName','请输入正确格式，账号只支持中文、中文加数字！',1,'callback'),
		array('branch','/^[\x7f-\xff]{3,20}$/','请输入正确格式，部门只支持中文！',1,'regex'),
		array('password','checkPwd','请输入正确格式，密码只支持6~16位字符密码！',1,'callback'),
		array('repassword','password','两次密码不相同！',1,'confirm'),
	);
	// 自定义的用户名验证
	public function checkName($username)
	{
		$pattern = '/^[0-9\x7f-\xff]+$/';
		if(!preg_match($pattern, $username)){
			return false;
		}else{
			return true;
		}
	}
	// 自定义的密码验证
	public function checkPwd($password)
	{
		$pattern = '/^[a-zA-Z0-9]{6,16}$/';
		if(!preg_match($pattern, $password)){
			return false;
		}else{
			return true;
		}
	}
}